package app.k.com.kframedemo;

import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.viewplug.view.scroll.WScrollView;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


public class MainActivity extends ActionBarActivity {

    private WScrollView wScrollView;
    private ListView listView;
    private List<Data> datas;
    private MyAdapter myAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initViews();
    }

    private void initViews() {
        datas = new ArrayList<Data>();
        initData();
        myAdapter = new MyAdapter();
        wScrollView = (WScrollView) findViewById(R.id.scrollview);
        wScrollView.setRefreshListener(new WScrollView.RefreshListener() {
            @Override
            public void onRefresh() {
                wScrollView.stopRefresh();
            }

            @Override
            public void onLoadMore() {

            }

            @Override
            public void onFirst() {

            }
        });
        listView = wScrollView.getmContentListView();
        listView.setAdapter(myAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(MainActivity.this,datas.get(position).aClass);
                startActivity(intent);
            }
        });
    }

    private void initData() {
        Data gua_data = new Data();
        gua_data.aClass = GuaGuaLeActicity.class;
        gua_data.name = "刮刮乐";
        datas.add(gua_data);

        Data tab_data = new Data();
        tab_data.aClass = TabFragmentHost.class;
        tab_data.name = "FragmentTabHost";
        datas.add(tab_data);

        Data chart_data = new Data();
        chart_data.aClass = CharActivity.class;
        chart_data.name = "统计图";
        datas.add(chart_data);

        Data reside_data = new Data();
        reside_data.aClass = ResideActivity.class;
        reside_data.name = "模仿qq侧拉";
        datas.add(reside_data);

        Data slice_data = new Data();
        slice_data.aClass = SliceActivity.class;
        slice_data.name = "模仿qq切图";
        datas.add(slice_data);

        Data text_data = new Data();
        text_data.aClass = TextArcActivity.class;
        text_data.name = "文字圆形边框";
        datas.add(text_data);

        Data text_data1 = new Data();
        text_data1.aClass = ChartActivity.class;
        text_data1.name = "统计图";
        datas.add(text_data1);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
    private class MyAdapter extends BaseAdapter{

        @Override
        public int getCount() {
            return datas.size();
        }

        @Override
        public Object getItem(int position) {
            return position;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView==null)
            {
                convertView = LayoutInflater.from(getApplicationContext()).inflate(android.R.layout.simple_list_item_1,null);
            }
            TextView textView = (TextView) convertView;
            textView.setText(datas.get(position).name);
            textView.setTextColor(getResources().getColor(android.R.color.holo_blue_light));
            return textView;
        }
    }
    private class Data{
        public String name;
        public Class aClass;
    }
}
